package com.hnu.highlynewapp.service.impl;

import com.hnu.highlynewapp.entity.ContactEntity;
import com.hnu.highlynewapp.entity.ServiceProductEntity;
import com.hnu.highlynewapp.service.ContactService;
import com.hnu.highlynewapp.vo.PublishTalentNeedVo;
import com.hnu.highlynewapp.vo.TalentNeedSearchVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnu.highlynewapp.utils.PageUtils;
import com.hnu.highlynewapp.utils.Query;

import com.hnu.highlynewapp.dao.TalentNeedDao;
import com.hnu.highlynewapp.entity.TalentNeedEntity;
import com.hnu.highlynewapp.service.TalentNeedService;
import org.springframework.util.StringUtils;


@Service("talentNeedService")
public class TalentNeedServiceImpl extends ServiceImpl<TalentNeedDao, TalentNeedEntity> implements TalentNeedService {

    @Autowired
    private ContactService contactService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TalentNeedEntity> page = this.page(
                new Query<TalentNeedEntity>().getPage(params),
                new QueryWrapper<TalentNeedEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public void publish(PublishTalentNeedVo vo) {
        ContactEntity contactEntity = new ContactEntity();
        BeanUtils.copyProperties(vo,contactEntity);
        contactEntity.setAddress(vo.getContactAddress());
        contactEntity.setPosition(vo.getContactPosition());
        Long contactId = contactService.saveAndCheckExist(contactEntity);

        TalentNeedEntity talentNeedEntity = new TalentNeedEntity();
        BeanUtils.copyProperties(vo,talentNeedEntity);
        talentNeedEntity.setAddress(vo.getBusinessAddress());
        talentNeedEntity.setPosition(vo.getBusinessPosition());
        talentNeedEntity.setPublishTime(new Date());
        talentNeedEntity.setContactId(contactId);
        baseMapper.insert(talentNeedEntity);
    }

    @Override
    public List<TalentNeedEntity> getListByParma() {

        QueryWrapper<TalentNeedEntity> wrapper = new QueryWrapper<>();

        wrapper.orderByDesc("publish_time");
        List<TalentNeedEntity> list = baseMapper.selectList(wrapper);
        return list;
    }

}